import 'dart:async';

import 'package:flutter/material.dart';

class BoxParentPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("box"),
      ),
      body: BoxParentWidget(),
    );
  }
}

class BoxParentWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return new _BoxParentWidget();
  }
}

class _BoxParentWidget extends State<BoxParentWidget> {
  bool _active = false;

  void _handleTapboxChange(bool newvalue) {
    setState(() {
      _active = newvalue;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Container(
      child: new TapBoxB(active: _active, onChange: _handleTapboxChange),
    );
  }
}

class TapBoxB extends StatelessWidget {
  final bool? active;
  final ValueChanged<bool>? onChange;

  TapBoxB({Key? key, this.active, @required this.onChange}) : super(key: key);

  void _handleTap() {
    onChange!(!active!);
  }

  @override
  Widget build(BuildContext context) {
    return new GestureDetector(
      onTap: _handleTap,
      child: new Container(
        child: new Center(
          child: new Text(
            active! ? 'Active' : 'Inactive',
            style: new TextStyle(
              fontSize: 32,
              color: Colors.white,
            ),
          ),
        ),
        width: 200,
        height: 200,
        decoration: new BoxDecoration(
          color: active! ? Colors.lightGreen[700] : Colors.grey[600],
        ),
      ),
    );
  }

// TapBoxB({Key key}):super(key: key)

}
